package com.desire.homework;

import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * 计算两日期之间的天数
 *
 * @author desire
 */
public class _04_计算两日期之间的天数 {
    public static void main(String[] args) throws ParseException {
        String t1 = "2020-12-12 00:00:00";
        String t2 = "2020-12-13 00:00:00";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 获取早时间的时间戳   getTime()获取时间戳
        long early = sdf.parse(t1).getTime();
        // 获取晚些时间的时间戳
        long late = sdf.parse(t2).getTime();
        // 计算差值,时间戳
        long date = late - early;
        //计算天数
        long resultDate = date / 1000 / 60 / 60 / 24;
        System.out.println(t1 + " ====== " + t2 + " 两天之间相差了 " + resultDate + " 天");
    }

}
